# -*- coding: utf-8 -*-
# @Time : 2022-01-06 10:58
# @Author : Z
# @Function :

# # replace,替换----------------
# a = '123456'
# b = a.replace('1', 'a')
# print(b)

# a = {"a": "1", "b": "2", "c": "3"}
# print(type(a))
# params = '123'
# params = params.replace('2', a.get('c'))
# print(params)


# # 要头不要尾------------
# a = '123456'
# print(a[1:])
# print(a[:1])


# 获取文件的绝对路径------------------
# import os
# path = os.path.realpath(__file__)
# print(path)
# # 将path分割成目录和文件名二元组返回
# path = os.path.split(path)
# path1 = path[0]
# print(path)
# print(path1)
# print(type(path))


# # find--------------
# a = '12345'
# b = a.find('2')
# print(b)


# 正则提取数字-------------
# import re
# str1 = 'ada123456789012345678da'
# text = re.findall(r'\d{18}', str1)[0]
# print(text)

# import re
# L = '订单号：  202201071039299006    |     付款金额（元）：  102.60 元'
# # print(re.findall(r'\d{18}', L))
# a = (re.findall('：  (.+?) ', L))
# print(a[0])
# for i in range(5):
#     print(a[i])

# s = 'abc'
# print(s.split(' '))
# params = '1'
# a = "{"+params+"}"
# print(a)


# # 关联-----------
# class Test:
#
#     def __init__(self):
#         # self.relations = {"a": "1", "b": "2", "c": "3"}
#         self.relations = {"a": "1", "b": "2", "c": "3", "d": "3"}
#
#     def get_relations(self, params: str = ''):
#         if params:
#             for key in self.relations:
#                 # params.replace(旧值，新值)   新值替换params的旧值，若旧值不存在params中，则保持原来数据
#                 params = params.replace('{'+key+'}', str(self.relations.get(key)))
#                 # print("替换后的参数："+params)
#         return params


# if __name__ == '__main__':
#     a = Test()
#     print(a.get_relations('{a}'))
#     # a.get_relations('{b}')
#     print(a.get_relations('1{c}'))
#     print(a.get_relations("c"))
#     # print(a.get_relations('{d}'))

# relations = {"a": "1", "b": "2", "c": "3", "d": "4"}
# for key in relations:
#     print(key+':'+relations[key])

# ll = ["蒜蓉西兰花", "红烧肉", "测试鸡汁菜心"]
#
# for i in ll:
#     print(i)
#     a = ('(//*[text()="'+ i + '"])/../../div[6]')
#     # b = ('//*[text()="’ + i '"]/../..//div[contains(text(),"已完成") ]')
#     b = ('(//*[text()="' + i + '"])/../../div'+'[contains(text(),"已完成") ]')
#     print(a)
#     print(b)

# a = []
# b = str(input('输入参数:'))
# a.append(b)
# print(a)

# d = '1'
# a = []
# while d == '1':
#     y = str(input('请输入参数：'))
#     a.append(y)
#     d = str(input('是否继续输入：1,0'))
# print(a)


# ll = ['广州炒饭', '蒜蓉西兰花', '蒜蓉炒菜花（V）',
#       '三丝炒米粉', '蒜蓉炒菜花（V）', '渝北胡辣鸡块',
#       '蒜蓉西兰花', '湘味小炒黄牛肉', '湘味小炒黄牛肉', '广州炒饭']
#
# ll = list(set(ll))
# print(ll)


# 格式化当前时间
# import datetime
# # 获取当前时间，时间数组格式
# now=datetime.datetime.now()
# time=now.strftime("%Y-%m-%d %H:%M:%S")
# print("当前时间是："+time)

# import time
# # 获取时间戳
# now=int(time.time())
# print("时间戳："+str(now))


# # json字符串转成字典
import json
import os

from jsonpath import jsonpath

# js = '{"a":"1","b":"2","c":3,"d":"5","e":"6"}'
# print(js)
# js_dir = json.loads(js)
# print("json字符串通过json.loads转换成字典：")
# print(js_dir)
# # print(type(js_dir))
# a = jsonpath(js_dir, '$.c')[0]
# # # print(type(a))
# print(a)
# js_str=json.dumps(js_dir)
# print(js_str)
# print(type(js_str))


# json_obj = {"name": "liusir", "age": 18}
# print(json_obj)
# print(type(json_obj))
# jj = {'a':'1','b':'2','c':'3'}
# llj = json.dumps(jj)
# print(llj)

# info_dict = {'name': 'Joe', 'age': 20, 'job': 'driver'}
# ll=json.dumps(info_dict)
# print("字典通过json.dumps转成json字符串："+ll)
# print(type(ll))

# # 字符串转数字
# str='2'
# print(type(str))
# ll=int(str)
# print(type(ll))

# # 数字转字符串
# num=123123
# ss='%d'%num
# print(type(ss))

# def add(x,y):
#     '''
#     @:param x:int
#     @:param y:int
#     @:return: int
#     '''
#     return x + y


# # 字符串加密
# import base64
# import hashlib

# str = 'I LOVE China! 我爱你中国！'
# str_en = str.encode('utf-8')
# print(str_en)
# print(str_en.decode('utf-8'))

# h = hashlib.md5(str_en)
# h.update('admin'.encode('utf-8'))
# h_en = h.hexdigest()
# print("md5加密：" + h_en)

# hh = hashlib.sha1(str_en)
# hh.update('admin'.encode('utf-8'))
# hh_en = h.hexdigest()
# print('sha1加密：' + hh_en)

# b64_en = base64.b64encode(str_en)
# print(b64_en)
# b64_de = base64.b64decode(b64_en)
# print(b64_de)
# str_de = b64_de.decode('utf-8')
# print(str_de)

# # 遍历列表的每一个元素，
# a = [1,2,3,4,5]
# for item  in a:
#     print(item)
# # 下标遍历列表
# for i in range(len(a)):
#     print(a[i])

# ll = 'a=1&b=2&c=3&d=4'
# # slipt 切片后，返回的是一个列表
# params = ll.split('&')
# print(params)
# # print(type(params))
# dict_a = {}
# for key_value in params:
#     print(key_value)
#     print(key_value.find('='))
#     key = key_value[:key_value.find('=')]
#     value = key_value[key_value.find('=')+1:]
#     dict_a[key] = value
# print(dict_a)
#
# dev = {}
# for i in range(len(params)):
#     key = params[i][:params[i].find('=')]

#     value = params[i][params[i].find('=')+1:]
#     dev[key] = value
# print(dev)

# class Test:
#
#     def __init__(self):
#         self.aa = {'a': '1', 'b': '2', 'c': '3', 'd': '4'}
#
#     def relation(self, param: str = ''):
#         if param:
#             # 遍历字典的键，如果param带有 {key},则用self.aa.get(key)替换，然后返回param
#             for key in self.aa.keys():
#                 param = param.replace('{' + key + '}', str(self.aa.get(key)))
#             return param
#
#
# if __name__ == '__main__':
#     test = Test()
#     print(test.relation('ll {a}  bb'))
#     print(test.relation("bb  {fafa}  aa"))


# # 字典遍历
# print("---------------aa遍历---------------------------------")
# aa = {'a': '1', 'b': '2', 'c': '3', 'd': '4'}
# for key in aa:
#     print(key+":"+aa.get(key))
#
# print("---------------aa.keys()遍历---------------------------------")
# for key in aa.keys():
#     print(key + ":" + aa.get(key))
#
# print("---------------aa.items遍历-------------------------------")
# for key,value in aa.items():
#     print(key+":" + value)


# 字符串转列表
a = 'abcdef1'
b = list(a)
print(b)
# 列表转字符串
aa = "".join(b)
print(aa)

# map将列表中的int类型数据转变为str,可以多看看api
c = [1, 2, 'a', 'b']
d = ','.join(map(str, c))
print(d)

# split() ，进行分割，返回一个列表
e = d.split(',')
print(e)

# replace() 替换，1为替换一次，不填默认替换所有
ll = 'abcdea'
ll = ll.replace('a', '1', 1)
print(ll)

# find(),将找到的字符串返回下标,找不到返回 -1
ll = '0123456789'
# print(ll.find(('8')))
ll = ll[ll.find('8'):]
print(ll)

a = [1]

if a:
    print(a)
else:
    print("b")


# 连接字符串数组。将字符串、元组、列表中的元素以指定的字符(分隔符)连接生成一个新的字符串
ll = ['a','b','c']
lll = '.'.join(ll)
print(lll)


# 合并目录
var = os.path.join('/hello/','good/boy/','doiido')
print(var)

ll = {'status': 200, 'msg': 'success', 'token': 'ba5147d796e8425eb269df39f5bd1101','a':[[1,2,3,4],[2,23,4,4]]}
ll_a = jsonpath(ll,'$.a')
print(ll_a)



